// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import Vue from 'vue'
import App from './App'
import VueResource from 'vue-resource'
import router from './router'
import axios from 'axios'

Vue.use(VueResource)
Vue.use(ElementUI)
Vue.config.productionTip = false
axios.defaults.baseURL = 'http://localhost:8000/gaitrec/api'

// 定义全局变量/函数
Vue.prototype.$axios = axios
Vue.prototype.setCookie = function(key, value, keepDays) {
  if (!keepDays) keepDays = 0
  var expireDate = new Date()
  expireDate.setTime(expireDate.getTime() + 24 * 60 * 60 * 1000 * keepDays)
  window.document.cookie = key + "=" + value + (keepDays == 0 ? "" : ";expires=" + expireDate.toGMTString())
}
Vue.prototype.getCookie = function(key) {
  var arr, reg = new RegExp("(^| )" + key + "=([^;]*)(;|$)")
  console.log(arr)
  console.log(window.document.cookie.match(reg))
  if (arr = window.document.cookie.match(reg))
    return arr[2]
  else
    return null
}
Vue.prototype.expireCookie = function(key) {
  this.setCookie(key, "", -1)
}

Vue.directive('title', {
  inserted: function (el, binding) {
    document.title = el.dataset.title
  }
})

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})
